﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using nRoute.Samples.SiteMapWeb.Data;
using System.Data.Objects;
using System.ServiceModel;

namespace nRoute.Samples.SiteMapWeb.Services
{
	[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
	public class SiteMapDataService : DataService<ObjectContext>
    {
		protected override ObjectContext CreateDataSource()
		{
			// see http://romiller.com/2010/07/19/ef-ctp4-tips-tricks-wcf-data-service-on-dbcontext/
			var _context = new ApplicationSiteMapContext();
			_context.InnerContext.ContextOptions.ProxyCreationEnabled = false;
			return _context.InnerContext;
		}

        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
			config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
			config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }
    }
}
